#!groovy
pipeline {
    agent any
    options {
        ansiColor(colorMapName: 'XTerm')
        disableConcurrentBuilds()
        timestamps()
    }
    parameters {
        string(name: 'version', defaultValue: '3.1.7', description: 'Teleport version to build')
    }
    stages {
        stage('Create files/build directory') {
            steps {
                dir('assets/marketplace') {
                    sh 'mkdir -p files/build'
                }
            }
        }
        stage('Run Packer to build specified version') {
            steps {
                dir('assets/marketplace') {
                    sh "PUBLIC_AMI_NAME=gravitational-teleport-ami-ent-${params.version} MARKETPLACE_AMI_NAME=gravitational-teleport-marketplace-ami-ent-${params.version} TELEPORT_VERSION=${params.version} make ent-jenkins-build"
                }
            }
        }
        stage('Make Enterprise AMIs public') {
            steps {
                dir('assets/marketplace') {
                    sh 'make change-amis-to-public-ent'
                }
            }
        }
    }
}
